<%@ page pageEncoding="utf-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html>

<html>

<head>

<title></title>

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<!-- 引入 Bootstrap -->

<link href="../css/bootstrap.min.css" rel="stylesheet">

<link href="../css/bootstrap-table.min.css" rel="stylesheet">

<script src="../js/jquery-1.11.3.min.js"></script>

<script src="../js/bootstrap.min.js"></script>

<script src="../js/bootstrap-table.min.js"></script>

<script src="../js/bootstrap-table-zh-CN.min.js"></script>

<style type="text/css">
#table-1 thead, #table-1 tr {
	border-top-width: 1px;
	border-top-style: solid;
	border-top-color: #a8bfde;
}

#table-1 {
	border-bottom-width: 1px;
	border-bottom-style: solid;
	border-bottom-color: #a8bfde;
}

/* Padding and font style */
#table-1 td, #table-1 th {
	padding: 5px 10px;
	font-size: 12px;
	font-family: Verdana;
	color: #5b7da3;
}

/* Alternating background colors */
#table-1 tr:nth-child(even) {
	background: #d3dfed
}

#table-1 tr:nth-child(odd) {
	background: #FFF
}
</style>

</head>

<body>

	<h1 style="color: #409EFF; text-align: center;">欢迎进入家族族谱管理员系统</h1>

	<hr>

		<div align="right">
		<a href="getUser.action">用户管理</a> <a href="findReport.action">审核举报</a>
		<a href="editUser.action">个人资料</a> <a href="${pageContext.request.contextPath}/logout.action">退出系统</a>
	</div>

	<p align="center">

		<a href="#" class="btn btn-info" data-toggle="modal"
			data-target="#newusersDialog">新建管理员</a>

	</p>

	<div id="page-wrapper">

		<table align="center" id="table-1">

			<tr>

				<th>序号</th>

				<th>用户名称</th>

				<th>密码</th>

				<th>性别</th>

				<th>联系方式</th>

				<th>身份</th>

				<th>管理</th>

			</tr>

			<c:forEach var="users" items="${users}" varStatus="vs">

				<tr>

					<td>${vs.count}</td>

					<td>${users.username}</td>

					<td>${users.password}</td>

					<td><c:choose>

							<c:when test="${users.sex == 0 }">女</c:when>

							<c:when test="${users.sex == 1 }">男</c:when>

						</c:choose></td>

					<td>${users.iphone}</td>

					<td><c:choose>

							<c:when test="${users.ident == 0 }">普通用户</c:when>

							<c:when test="${users.ident == 1 }">族谱编纂人员</c:when>

							<c:when test="${users.ident == 2 }">管理员</c:when>

						</c:choose></td>

					<td><a href="#" class="btn btn-primary btn-xs"
						data-toggle="modal" data-target="#usersEditDialog"
						onclick="editusers(${users.user_id})">修改</a> <a href="#"
						class="btn btn-danger btn-xs"
						onclick="deleteusers(${users.user_id})">删除</a></td>

				</tr>

			</c:forEach>

		</table>

	</div>



	<!-- 创建管理员模态框 -->

	<div class="modal fade" id="newusersDialog" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel">

		<div class="modal-dialog" role="document">

			<div class="modal-content">

				<div class="modal-header">

					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">

						<span aria-hidden="true">&times;</span>

					</button>

					<h4 class="modal-title" id="myModalLabel">新增管理员信息</h4>

				</div>

				<div class="modal-body">

					<form class="form-horizontal" id="new_users_form">



						<div class="form-group">

							<label for="new_username" class="col-sm-2 control-label">

								用户名 </label>

							<div class="col-sm-10">

								<input type="text" class="form-control" id="new_username"
									placeholder="用户名" name="username" />

							</div>

						</div>

						<div class="form-group">

							<label for="new_password" class="col-sm-2 control-label">密码</label>

							<div class="col-sm-10">

								<input type="text" class="form-control" id="new_password"
									placeholder="密码" name="password" />

							</div>

						</div>

						<div class="form-group">

							<label for="new_sex" class="col-sm-2 control-label">性别</label>

							<div class="col-sm-10">

								<select class="form-control" id="new_sex" name="sex">

									<option>--请选择--</option>

									<option value="0">女</option>

									<option value="1">男</option>

								</select>

							</div>



						</div>

						<div class="form-group">

							<label for="new_iphone" class="col-sm-2 control-label">手机号</label>

							<div class="col-sm-10">

								<input type="text" class="form-control" id="new_iphone"
									placeholder="手机号" name="iphone" />

							</div>

						</div>

						<div class="form-group">

							<label for="new_ident"
								style="float: left; padding: 7px 15px 0 27px;">系统权限</label>

							<div class="col-sm-10">

								<select class="form-control" id="new_ident" name="ident">

									<option>--请选择--</option>

									<option value="2">管理员</option>

								</select>

							</div>

						</div>





					</form>

				</div>

				<div class="modal-footer">

					<button type="button" class="btn btn-default" data-dismiss="modal"
						onclick="clearusers()">关闭</button>

					<button type="button" class="btn btn-primary"
						onclick="createusers()">创建系统管理员</button>

				</div>

			</div>

		</div>

	</div>



	<div class="modal fade" id="usersEditDialog" tabindex="-1"
		role="dialog" aria-labelledby="myModalLabel">

		<div class="modal-dialog" role="document">

			<div class="modal-content">

				<div class="modal-header">

					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">

						<span aria-hidden="true">&times;</span>

					</button>

					<h4 class="modal-title" id="myModalLabel">修改用户信息</h4>

				</div>

				<div class="modal-body">

					<form class="form-horizontal" id="edit_users_form">

						<input type="hidden" id="edit_user_id" name="user_id" />



						<div class="form-group">

							<label for="edit_username" class="col-sm-2 control-label">

								用户名 </label>

							<div class="col-sm-10">

								<input type="text" class="form-control" id="edit_username"
									placeholder="用户名" name="username" />

							</div>

						</div>

						<div class="form-group">

							<label for="edit_password" class="col-sm-2 control-label">密码</label>

							<div class="col-sm-10">

								<input type="text" class="form-control" id="edit_password"
									placeholder="密码" name="password" />

							</div>

						</div>

						<div class="form-group">

							<label for="edit_sex" class="col-sm-2 control-label">用户性别</label>

							<div class="col-sm-10">

								<input type="text" class="form-control" id="edit_sex"
									placeholder="用户性别" name="sex" />

							</div>

						</div>

						<div class="form-group">

							<label for="edit_iphone" class="col-sm-2 control-label">手机号</label>

							<div class="col-sm-10">

								<input type="text" class="form-control" id="edit_iphone"
									placeholder="手机号" name="iphone" />

							</div>

						</div>

						<div class="form-group">

							<label for="edit_ident"
								style="float: left; padding: 7px 15px 0 27px;">系统权限</label>

							<div class="col-sm-10">

								<select class="form-control" id="edit_ident" name="ident">

									<option>--请选择--</option>

									<option value="0">普通用户</option>

									<option value="1">系统编纂人员</option>

									<option value="2">管理员</option>

								</select>

							</div>

						</div>



					</form>

				</div>

				<div class="modal-footer">

					<button type="button" class="btn btn-default" data-dismiss="modal"
						onclick="cleargood()">关闭</button>

					<button type="button" class="btn btn-primary"
						onclick="updateusers()">修改用户</button>

				</div>

			</div>

		</div>





	</div>

</body>

<script type="text/javascript">



$("img").click(function(){

    var at=$(this).attr("src")

    $("#touimg").attr("src",at)

})





//清空新建商品分类窗口中的数据

	function clearusers() {

	    $("#new_username").val("");

	    $("#new_password").val("");

	    $("#new_sex").val("");

	    $("#new_iphone").val("");

	    $("#new_ident").val("");

	}

	//清空新建商品分类窗口中的数据

	function cleargood() {

	    $("#edit_username").val("");

	    $("#edit_password").val("");

	    $("#edit_sex").val("");

	    $("#edit_iphone").val("");

	    $("#edit_ident").val("");

	}

	

	function createusers() {



	$.post("${pageContext.request.contextPath}/create.action",

			

	$("#new_users_form").serialize(),function(data){

	        if(data =="OK"){

	            alert("管理员用户创建成功！");

	            window.location.reload();

	        }else{

	            alert("管理员用户创建失败！");

	            window.location.reload();

	        }

	        

	    });

	

	}

	

	function editusers(user_id) {

		

		$.post("${pageContext.request.contextPath}/getUserById.action",{"user_id":user_id},function(data){

			 $("#edit_user_id").val(data.user_id);

	         $("#edit_username").val(data.username);

	         $("#edit_password").val(data.password);

	         $("#edit_sex").val(data.sex);

	         $("#edit_iphone").val(data.iphone);	         

	         $("#edit_ident").val(data.ident);





		});

	}

	

	function updateusers() {

    	

		$.post("${pageContext.request.contextPath}/admin/update.action",$("#edit_users_form").serialize(),function(data){

			if(data =="OK"){

				alert("用户信息更新成功！");

				window.location.reload();

			}else{

				alert("用户信息更新失败！");

				window.location.reload();

			}

		});

	}

	

	function deleteusers(user_id) {

	    if(confirm('确实要删除该用户吗?')) {

	$.post("${pageContext.request.contextPath}/deleteUser.action",{"user_id":user_id},

	function(data){

	            if(data =="OK"){

	                alert("用户删除成功！");

	                window.location.reload();

	            }else{

	                alert("删除用户失败！");

	                window.location.reload();

	            }

	        });

	    }

	}

	

</script>

</html>

<%@include file="/WEB-INF/footer.jsp"%>
